package StudyCode.summary.myfile;

import java.io.*;
import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetBytesFromInputStream {
	public static void main(String[] argv) throws Exception {
		File file = new File("E:\\CODE\\JAVA\\ReviewCode\\src\\StudyCode\\summary\\myfile\\GetBytesFromInputStream.java");
		InputStream inputStream = new FileInputStream(file);
		System.out.println(Arrays.toString(getBytesFromStream(inputStream)));
	}


	private static byte[] getBytesFromStream(InputStream is)
			throws IOException {
		int BUFFER_SIZE = 8192;
		byte[] buffer = new byte[BUFFER_SIZE];
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		int numRead = 0;
		while ((numRead = is.read(buffer)) > 0) {
			os.write(buffer, 0, numRead);
		}
		return os.toByteArray();
	}
}
